<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>住户列表</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>

    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}"
          rel="stylesheet">
    <!-- Morris -->
    <link href="../../resource/css/plugins/morris/morris-0.4.3.min.css"
          th:href="@{/resource/css/plugins/morris/morris-0.4.3.min.css}" rel="stylesheet">

    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>

    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">

    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="../../resource/hotui/css/switchery.min.css"
           th:href="@{/resource/hotui/css/switchery.min.css}" rel="stylesheet"/>
    <link href="../../resource/lib/bootstrap-daterangepicker/daterangepicker.min.css"
          th:href="@{/resource/lib/bootstrap-daterangepicker/daterangepicker.min.css}" rel="stylesheet">
    <link href="../../resource/lib/bootstrap-datepicker/css/bootstrap-datepicker.min.css"
          th:href="@{/resource/lib/bootstrap-datepicker/css/bootstrap-datepicker.min.css}" rel="stylesheet"/>

    <link href="../../resource/hotui/css/awesome-bootstrap-checkbox.min.css" th:href="@{/resource/hotui/css/awesome-bootstrap-checkbox.min.css}"
          rel="stylesheet">

    <style type="text/css">
        .hr-line-dashed {
            margin: 10px 0;
            height: 1px;
            border-top: 1px dashed #e7eaec;
            background-color: #fff;
            color: #fff;
        }

        .city-picker-selector select {

        }

        .nav-tabs input {
            width: 20px;
            height: 23px;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get" th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                            <div class="form-group m-r-sm">
                                <label class="control-label">部门名称：</label>
                                <input type="text" class="form-control input-sm mb10" id="name" name="orgName"
                                       th:value="*{orgName}"
                                       placeholder=""/>
                            </div>
                            <div style="float: right;">
                                <button type="button" class="btn btn-success" onclick="jsHelper.search()">筛选</button>
                                <button type="button" class="btn btn-success" onclick="jsHelper.searchAll()">显示全部
                                </button>
                                <button type="button" class="btn btn-success" onclick="jsHelper.setResident()">添加
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->

    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body">
                                <table class="table table-bordered table-hover table-center">
                                    <tr>
                                        <th>序号</th>
                                        <th>部门名称</th>
                                        <th>部门描述</th>
                                        <th>操作</th>
                                    </tr>
                                    <tr th:each="org,index:${orgList}">
                                        <td th:text="${index.index+1}"></td>
                                        <td th:text="${org.name}"></td>
                                        <td>
                                            <span th:text="${org.description}"></span>
                                        </td>
                                        <td>
                                            <button th:onclick="jsHelper.setResident([[${org.orgId}]],[[${org.name}]],[[${org.description}]])"
                                                    type="button" class="btn btn-info btn-xs m-b-none">
                                                编辑
                                            </button>
                                            <button th:onclick="jsHelper.showWorker([[${org.name}]],[[${org.orgId}]])"
                                                    type="button" class="btn btn-info btn-xs m-b-none">
                                                人员列表
                                            </button>
                                            <button th:onclick="jsHelper.del([[${org.orgId}]])"
                                                    type="button" class="btn btn-danger btn-xs m-b-none">
                                                删除
                                            </button>
                                        </td>
                                    </tr>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span th:text="${pageIndex}"></span>/<span
                                        th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul style="float: right;" class="pagination pagination-split">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="set_resident_modal" class="modal-content-tag">
    <form id="residentModelForm">
        <div class="form-group">
            <label class="col-sm-4 control-label">部门名称：</label>
            <div class="col-sm-8">
                <input id="modelOrgId" name="modelOrgId" minlength="2" type="hidden" class="form-control"
                       value="0">
                <input id="modelOrgName" type="text" class="form-control" name="modelOrgName">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label">描述：</label>
            <div class="col-sm-8">
                <textarea id="modelDesc" type="text" class="form-control" name="modelDesc"></textarea>
            </div>
        </div>
    </form>
</div>

<!--基础框架js-->
<script src="../../resource/js/jquery.min.js" th:src="@{/resource/js/jquery.min.js?20190316}"></script>
<script src="../../resource/js/bootstrap.min.js" th:src="@{/resource/js/bootstrap.min.js?20190316}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316?1234567"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316(123)}"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>

<script src="../../resource/hotui/js/plugins/datetimepick/js/moment.min.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/moment.min.js}" ></script>
<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>

<script src="../../resource/lib/bootstrap-datepicker/js/bootstrap-datepicker.min.js"
        th:src="@{/resource/lib/bootstrap-datepicker/js/bootstrap-datepicker.min.js}"></script>
<script src="../../resource/lib/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.min.js"
        th:src="@{/resource/lib/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.min.js}"></script>

<script src="../../resource/js/switchery.min.js" th:src="@{/resource/js/switchery.min.js}"></script>

<script src="../../resource/js/plugins/validate/jquery.validate.min.js"
        th:src="@{/resource/js/plugins/validate/jquery.validate.min.js}" ></script>

<script src="../../resource/js/plugins/validate/messages_zh.min.js"
        th:src="@{/resource/js/plugins/validate/messages_zh.min.js}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-validate.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-validate.js}"></script>

<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  0;
    const pageUri = /*[[@{/resident/org/list}]]*/  "";
    const equipmentApiBase = /*[[@{/resident}]]*/  "/resident";
    const workerList = /*[[@{/resident/worker/list}]]*/  "";
</script>

<script>
    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            jsHelper.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                $(".searchBtn").trigger("click");
            }
        });

        $("input[name=chkAll]").change(function () {
            if ($(this).prop("checked")) {
                $("input[name=chkUser]").prop("checked", "checked");
            } else {
                $("input[name=chkUser]").removeAttr("checked");
            }
        });
        jsHelper.init();
    });

    var setResidentModel = $("#set_resident_modal").modal("部门信息", function () {
        $("#residentModelForm").submit();
    });

    var jsHelper = {
        init: function () {
        },
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri;
        },
        showWorker: function (orgName, orgId) {
            hot.iframeModal(workerList + "?orgId=" + orgId, '100%', '100%', orgName);
        },
        setResident: function (id, name, description) {
            setResidentModel.show(function () {
                if (id != null) {
                    $("#modelOrgId").val(id);
                    $("#modelOrgName").val(name);
                    $("#modelDesc").val(description);
                }
                $("#residentModelForm").validateCallback(function () {
                    var requestData = {
                        orgId: $("#modelOrgId").val(),
                        orgName: $("#modelOrgName").val(),
                        desc: $("#modelDesc").val()
                    };

                    hot.ajax(equipmentApiBase + "/save/org", requestData, function (apiResult) {
                        if (apiResult.resultCode === 2000) {
                            setResidentModel.hide(function () {
                                hot.tip.success("操作成功");
                                window.location.reload();
                            });
                        } else {
                            hot.tip.error("操作失败--" + apiResult.resultMsg);
                        }
                    }, function () {
                    }, "post", 300);
                })
            });
        },
        del: function (id) {
            hot.confirm("确定要删除该部门吗？", function () {
                var requestData = {
                    id: id,
                };
                hot.ajax(equipmentApiBase + "/del/org", requestData, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        setResidentModel.hide(function () {
                            hot.tip.success("删除成功");
                            window.location.reload();
                        });
                    } else {
                        hot.tip.error("删除失败--" + apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            });
        },
    };
</script>
</body>
</html>
